#include <iostream>
#include <vector>

using namespace std;
void findArround(int i, int j, vector<vector<int>> &M)
{
    int r = M.size();    //row
    int c = M[0].size(); //column
    //左
    if (j - 1 >= 0 && M[i][j - 1])
    {
        M[i][j - 1] = 0;
        findArround(i, j - 1, M);
    }

    //右
    if (j + 1 < c && M[i][j + 1])
    {
        M[i][j + 1] = 0;
        findArround(i, j + 1, M);
    }

    //上
    if (i - 1 >= 0 && M[i - 1][j])
    {
        M[i - 1][j] = 0;
        findArround(i - 1, j - 1, M);
    }

    //下
    if (i + 1 < r && M[i + 1][j])
    {
        M[i + 1][j] = 0;
        findArround(i + 1, j, M);
    }
}

int findCircleNum(vector<vector<int>> &M)
{
    int r = M.size();    //row
    int c = M[0].size(); //column
    int circle = 0;

    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            if (M[i][j])
            {
                circle++;
                M[i][j] = 0;
                findArround(i, j, M);
            }
        }
    }

    return circle;
}

int main()
{
    int arr[3][3] =
        {1, 1, 0, 1, 1, 0, 0, 0, 1};

    int r, c;
    cin >> r;
    cin >> c;

    vector<vector<int>> M(r, vector<int>(c));
    for (int i = 0; i < r; i++)
        for (int j = 0; j < c; j++)
            M[i][j] = arr[i][j];
    // cin >> M[i][j];

    int num = findCircleNum(M);
    cout << num << endl;
    return 0;
}

/*
1,0,0,1,0,1,1,0,0,1,1,1,1,0,1,1
*/